package com.ruoyi.web.controller.sms;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.sms.entity.Shop;
import com.ruoyi.sms.entity.ShopVO;
import com.ruoyi.sms.service.IShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

/**
 * 商家管理Controller
 *
 * @author ruoyi
 * @date 2021-11-04
 */
@RestController
@RequestMapping("/sms/shop")
public class SmsShopController extends BaseController {
    @Autowired
    private IShopService smsShopService;

    /**
     * 查询商家管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:shop:list')")
    @GetMapping("/list")
    public TableDataInfo list(ShopVO smsShop) {
        startPage();
        List<ShopVO> list = smsShopService.selectShop(smsShop);
        return getDataTable(list);
    }

    /**
     * 导出商家管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:shop:export')")
    @Log(title = "商家管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ShopVO smsShop) {
        List<ShopVO> list = smsShopService.selectShop(smsShop);
        ExcelUtil<ShopVO> util = new ExcelUtil<ShopVO>(ShopVO.class);
        return util.exportExcel(list, "商家管理数据");
    }

    /**
     * 获取商家管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:shop:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(smsShopService.selectShopById(id));
    }

    /**
     * 新增商家管理
     */
    @PreAuthorize("@ss.hasPermi('system:shop:add')")
    @Log(title = "商家管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Shop smsShop) {
        return toAjax(smsShopService.insertShop(smsShop));
    }

    /**
     * 修改商家管理
     */
    @PreAuthorize("@ss.hasPermi('system:shop:edit')")
    @Log(title = "商家管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Shop smsShop) {
        return toAjax(smsShopService.updateById(smsShop));
    }

    /**
     * 删除商家管理
     */
    @PreAuthorize("@ss.hasPermi('system:shop:remove')")
    @Log(title = "商家管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        List<Long> list = Arrays.asList(ids);
        return toAjax(smsShopService.removeByIds(list));
    }
}